<!DOCTYPE html>
<html>
<head>
    <title>设备维护工单</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div>
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="search-group">
                <i-col span="4">
                    <i-input v-model="q.name" @on-enter="query" placeholder="设备名称"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.repairCode" @on-enter="query" placeholder="工单编号"></i-input>
                </i-col>
                <i-col span="4">
                    <Date-picker :disabled="isDisabled" type="date" v-model="q.beginTime"
                                 placeholder="工单查询开始时间"></Date-picker>
                </i-col>
                <i-col span="4">
                    <Date-picker :disabled="isDisabled" type="date" v-model="q.endTime"
                                 placeholder="工单查询结束时间"></Date-picker>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>
</div>

<script>
    $(function () {
        $("#jqGrid").Grid({
            url: '../devplangc/list',
            colModel: [
            {label: '工单号', name: 'repairCode', index: 'REPAIR_CODE', width: 80},
            {label: '单位', name: 'workshopName', width: 80},
            {label: '区域', name: 'productLineName', width: 80},
            {label: '工序号', name: 'proceNo', width: 80},
            {label: '设备名称', name: 'devName', index: 'DEV_ID', width: 80},
            {
                label: '开始日期', name: 'startTime', index: 'START_TIME', width: 80,
                formatter: function (v) {
                    return transDate(v, 'yyyy-MM-dd')
                }
            },
            {
                label: '结束日期', name: 'endTime', index: 'START_TIME', width: 80,
                formatter: function (v) {
                    return transDate(v, 'yyyy-MM-dd')
                }
            },
            {
                label: '状态', index: 'STATUS', width: 80, formatter: function (value, col, row) {
                    var v = row.status;
                    return sysEnums.MAINTENANCE_TICKET_STATUS[v];
                }
            },
            {
                label: '工单类别', name: 'ticketType', index: 'TICKET_TYPE', width: 80, formatter: function (value, col, row) {
                    return sysEnums.TICKET_TYPE[row.ticketType];
                }
            },
            {label: '实施人', name: 'executorName', index: 'EXECUTOR', width: 80},
            {
                label: '详情', width: 50, sortable: false,
                formatter: function (value, col, row) {
                    return "<button class='btn btn-outline btn-info' id='recordsText' onclick='vm.gdDetail(\"" + row.id + "\",\"" + row.ticketType + "\")'>&nbsp;<i class='fa fa-qrcode'></i></button>";
                }
            },
            {
                label: '异常查看', sortable: false, width: 50,
                formatter: function (value, col, row) {
                    return "<button class='btn btn-outline btn-info' id='showText' onclick='vm.ycDetail(\"" + row.id + "\")'>&nbsp;<i class='fa fa-file-text-o'></i></button>";
                }
            },
            {name: 'devId', hidden: true},
            {name: 'isUrged', hidden: true},
            {name: 'approvalStatus', hidden: true},
            {name: 'status', hidden: true},
            {label: 'id', name: 'id', index: 'ID', key: true, hidden: true}
            ]
        });
    });

    let vm = new Vue({
        el: '#rrapp',
        data: {
            q: {
                name: '',
                repairCode:'',
                beginTime: '',
                endTime: ''
            },
            isDisabled: false
        },
        methods: {
            query: function () {
                vm.reload();
            },
            reload: function (event) {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');

                var beginTime = vm.q.beginTime;
                if (beginTime != "" && beginTime != "null") {
                    var date = new Date(beginTime);
                    // beginTime = date.format("yyyy-MM-dd");
                    beginTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                }
                var endTime = vm.q.endTime;
                if (endTime != "" && endTime != "null") {
                    var date = new Date(endTime);
                    endTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                }

                $("#jqGrid").jqGrid('setGridParam', {
                    postData: {
                        'repairCode':vm.q.repairCode,
                        'devName': vm.q.name,
                        'beginTime': beginTime,
                        'endTime': endTime
                    },
                    page: page
                }).trigger("reloadGrid");
                vm.handleReset('setGridParam');
            },
            reloadSearch: function () {
                vm.q = {
                    repairCode:'',
                    name: '',
                    beginTime: '',
                    endTime: ''
                };
                vm.reload();
            },
            handleSubmit: function (name) {
                handleSubmitValidate(this, name, function () {
                    vm.saveOrUpdate()
                });
            },
            handleReset: function (name) {
                handleResetForm(this, name);
            }
        }
    });

    var getSparePart = function () {
        let result = getSelectedRowData("#jqGrid");
        var id = result.id;
        if (id == null) {
            return false;
        } else {
            return result;
        }
    }
</script>
</body>
</html>
